{extend name="default/template/base_index" /}

{block name="area_header"}

    <link type="text/css" rel="stylesheet" href="__CDN__/select2/4.0.0/css/select2.min.css" />
    <link type="text/css" rel="stylesheet" href="__CDN__/select2/4.0.0/css/cosmo-skin.css" />
{/block}

{block name="area_body"}
    {include file="default/Widget/topbar" /}
    <div class="admin-main container-fluid">
        {include file="default/Widget/left" /}
        <div class="admin-main-content">
            {include file="default/Widget/breadcrumb" /}

            <!-- 带验证 form -->
            <form class="form-horizontal well validateForm" >
                <fieldset>
                    <legend>
                        发送红包</legend>

                    <div class="form-group">
                        <label for="type" class="col-md-2 col-lg-2 control-label">发送给：</label>
                        <div class="col-md-10 col-lg-10">
                            <select id="user_select2" name="uid" class="form-control">

                            </select>
                            <div class="help-block">(获得该红包的用户)</div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="type" class="col-md-2 col-lg-2 control-label">备注：</label>
                        <div class="col-md-10 col-lg-10">
                            <textarea class="form-control" name="notes" rows="5"></textarea>
                            <div class="help-block">()</div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="btns" class="col-md-2 col-lg-2 control-label">&nbsp;</label>
                        <div class="col-lg-10 col-md-10">
                            <a target-form="validateForm" class="ajax-post btn btn-primary" onclick="return getData();" href="{:url('RedEnvelopeTpl/giveRedEnvelope',array('id'=>$id))}" autofocus="autofocus"><i class="fa fa-save"></i> {:L('BTN_SAVE')}</a>
                            <a class="btn btn-default" href="{:url('RedEnvelopeTpl/index')}"><i class="fa fa-times-circle"></i> {:L('BTN_CANCEL')}</a>
                        </div>
                    </div>
                </fieldset>

            </form>
            <div>
                <h3>用户获得该红包记录</h3>
                <table class="table table-border table-hover">
                    <thead>
                        <tr>
                            <th>获得红包用户ID、昵称</th>
                            <th>红包类别</th>
                            <th>有效期</th>
                            <th>使用状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    {volist name="list" id="vo"}
                        <tr>
                            <td>
                                {$vo.uid}|{$vo.nickname}
                            </td>
                            <td>
                                {$vo.dtree_type_name}
                            </td>
                            <td>
                                {$vo.get_time|date='Y-m-d H:i:s',###}至{:date('Y-m-d H:i:s',$vo['expire_time'])}
                            </td>
                            <td>
                                <eq name="vo['use_status']" value="0">
                                    未使用
                                    {else/}
                                    已使用
                                {/eq}
                            </td>
                            <td>

                            </td>
                        </tr>

                    {/volist}

                    </tbody>
                </table>
                {$show}
            </div>
        </div>
        <!-- END admin-main-content -->
    </div>
    <!-- END admin-main-->
{/block}

{block name="area_footer"}


    <script src="__CDN__/select2/4.0.0/js/select2.min.js"></script>
    <script src="__CDN__/select2/4.0.0/js/i18n/zh-CN.js"></script>
    <script type="text/javascript">

        $(function(){


            $("#user_select2").select2({
                placeholder: "输入用户id或昵称查询"	,
                language: "zh-CN",
                ajax: {
                    url: "{:url('Member/select')}",
                    dataType: 'json',
                    delay: 250,
                    data: function (params) {
                        var queryParameters = {
                            q: params.term
                        }
                        return queryParameters;

                    },
                    processResults: function (data, page) {
                        if(!data.info){
                            data.info = new Array();
                            data.info['nodata']="无相关数据";
                        }
                        // parse the results into the format expected by Select2.
                        // since we are using custom formatting functions we do not need to
                        // alter the remote JSON data
                        return {
                            results: data.info
                        };
                    },
                    cache: true
                },
                minimumInputLength: 0,
                templateSelection: function (repo) {
                    var selection = repo.nickname || repo.text;
                    if(repo.nickname){

                    }
                    return selection;
                },
                templateResult: function (repo) {

                    if (repo.loading) return repo.text;
                    if(repo.nodata) return repo.nodata;
                    var markup = '<div><img src="'+repo.head+'" style="width:30px;height:30px;"/>[id:'+repo.id+'] '+repo.nickname+'</div>';
                    return $(markup);
                },
            });

        })
    </script>
{/block}